package br.edu.ifrn.utineo.web;

import br.edu.ifrn.utineo.jdbc.Conexao;
import br.edu.ifrn.utineo.modelo.Sistema;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class NavegacaoServlet
 */
public class NavegacaoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NavegacaoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 String pagina = request.getParameter("pagina");
                 int medID=0;
                 String parametro = request.getParameter("medico");
                 if(parametro!=null){
                    medID = Integer.parseInt(request.getParameter("medico"));
                 }
                 Sistema sis = Sistema.getInstance();


            if (pagina.equalsIgnoreCase("cadastrar_paciente")){
                request.setAttribute("medico",  sis.getFuncionario(medID) );
                RequestDispatcher dispatcher = request.getRequestDispatcher("medico/cadastrar_paciente.jsp");
		dispatcher.forward(request, response);
               
                return;
            }

            if (pagina.equalsIgnoreCase("gerar_prescricao")){
            
                request.setAttribute("medico", medID);
                RequestDispatcher dispatcher = request.getRequestDispatcher("medico/localizar_registro.jsp");
                dispatcher.forward(request, response);
                return;
            }

            if (pagina.equalsIgnoreCase("consultar_pacientes")){
            
                request.setAttribute("medico",  medID );
                RequestDispatcher dispatcher = request.getRequestDispatcher("medico/consultar_pacientes.jsp");
		dispatcher.forward(request, response);
               
                return;
            }

            if (pagina.equalsIgnoreCase("editar_prescricao")){
          
                 request.setAttribute("medico",  medID );
                 RequestDispatcher dispatcher = request.getRequestDispatcher("medico/editar_prescricao.jsp");
	   	 dispatcher.forward(request, response);

                return;
            }
              

            if (pagina.equalsIgnoreCase("cadastrar_usuario")){
                response.sendRedirect("administrador/cadastrar_usuario.jsp");
            }

            if (pagina.equalsIgnoreCase("visualizar_cadastros")){
                response.sendRedirect("administrador/visualizar_cadastros.jsp");
            }

            if (pagina.equalsIgnoreCase("editar_cadastros")){
                response.sendRedirect("administrador/editar_dados.jsp");
            }

            if (pagina.equalsIgnoreCase("excluir_cadastro")){
                response.sendRedirect("administrador/excluir_cadastro.jsp");
            }

            if (pagina.equalsIgnoreCase("visualizar_prescricao")){
                response.sendRedirect("farmacia/visualizar_prescricao.jsp");
            }

            if (pagina.equalsIgnoreCase("index")){
                response.sendRedirect("index.jsp");
                return;
            }
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           
	}

}
